// pages/new-list/new-list.js
var app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ClassificationAll:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    var ClassificationlistUrl=app.globalData.it120Base +"/liujiahe/cms/category/list";
    this.getClassificationListData(ClassificationlistUrl,"ClassificationAll","全部类别");
    wx.showNavigationBarLoading({
      complete: (res) => {},
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getClassificationListData:function(url,settedKey,categoryTitle){
    var that = this;
    wx.request({
      method:'GET',
      url: url,
      success:function(res){
        that.processClassificationList(res.data,settedKey,categoryTitle);
        console.log(res.data);
      },
      fail:function(error){
        console.log(error)
      }
    })
  },

  processClassificationList:function(moviesDouban,settedKey,categoryTitle){
    var Classification=[];
    for (var idx in moviesDouban.data){
      var subject=moviesDouban.data[idx];
      var name=subject.name;
      if(name.length>=6){
        name=name.substring(0,6)+"...";
      }
      var remark=subject.remark;
      if(remark.length>=18){
        remark=remark.substring(0,18)+"...";
      }
      var temp={
        name:name,
        remark:remark,
        ClassificationIcon:subject.icon,
        ClassificationId:subject.id
      }
      Classification.push(temp)
    }

    var readyData={};
    readyData[settedKey]={
      categoryTitle:categoryTitle,
      Classification:Classification
    }
    this.setData(readyData);
    wx.hideNavigationBarLoading({
      complete: (res) => {},
    })
  },
  onNewlistToNewid:function(event){
    var newListId=event.currentTarget.dataset.listId;
    console.log(newListId);
    wx.navigateTo({
      url: '../article-list/article-list?id='+newListId,
    })
  }
})